#!/bin/python
#-*- coding:utf-8 -*-
# Filename:    main.py
# Revision:    1.0
# Date:        2012-06-14
# Author:      simonzhang
# web:         www.simonzhang.net
# Email:       simon-zzm@163.com
### END INIT INFO
import sys
import tornado.ioloop
import tornado.locale
import tornado.web
import time
import random

from config import *
from login import *
from index import *
from deploy import *
from project_set import *
from del_package import *
from del_file import *
from single_server import *
from set_up import *
from global_set import *
from upload import *
from makepackage import *
from info_help import *


settings = {
    "cookie_secret": cookie_key,
    "login_url": "/",
    "static_path":"static",
    "debug":True,
}


class NotFoundPage(BaseHandler):
    def get(self):
        self.set_status(404)
        self.render('templates/error.html')


application = tornado.web.Application([
    (r"/", LoginHandler),
    (r"/index/", MainHandler),
    (r"/index/make_package/", MakePackageHandler),
    (r"/index/make_package/projecttree/", ProjectTreeHandler),
    (r"/index/make_package/getverserverinfo/", GetVerServerInfoHandler),
    (r"/index/upload/zipupload/", ZipUploadHandler),
    (r"/index/upload/oneupload/", OneUploadHandler),
    (r"/index/upload/versionload/", VersionLoadHandler),
    (r"/index/deploy/", DeployHandler),
    (r"/index/deploy/getprojectdeploy/", GetProjectDeployHandler),
    (r"/index/deploy/get_deploy_status/", GetDeployStatusHandler),
    (r"/index/deploy/playbacklog/", PlaybackLogHandler),
    (r"/index/deploy/getprojectpackage/", GetProjectPackageHandler),
    (r"/index/project_set/", ProjectSetHandler),
    (r"/index/project_set/getprojectset/", GetProjectSetHandler),
    (r"/index/project_set/projectdefault/", ProjectDefaultHandler),
    (r"/index/project_set/uploadconfile/", UploadConfileHandler),
    (r"/index/project_set/downconfile/", DownConfileHandler),
    (r"/index/project_set/delservice/", DelServiceHandler),
    (r"/index/project_set/editsvn/", EditSvnHandler),
    (r"/index/project_set/editgit/", EditGitHandler),
    (r"/index/project_set/testvercon/", TestVerConHandler),
    (r"/index/project_set/vermandefault/", VerManDefaultHandler),
    (r"/index/project_set/unlock/", UNLockHandler),
    (r"/index/del_package/", DelPackageHandler),
    (r"/index/del_package/getdelpackage/", GetDelPackageHandler),
    (r"/index/del_file/", DelFileHandler),
    (r"/index/del_file/get_delete_file_status/", GetDeteleFileStatusHandler),
    (r"/index/single_server/", SingleServerHandler),
    (r"/index/single_server/singledo/", SingleDoHandler),
    (r"/index/single_server/getserverstatus/", GetServerStatusHandler),
    (r"/index/single_server/checkserverstatus/", CheckServerStatusHandler),
    (r"/index/set_up/", SetUpHandler),
    (r"/index/global_set/", GlobalSetHandler),
    (r"/index/global_set/webinfo/", WebInfoHandler),
    (r"/index/global_set/adduser/", AddUserHandler),
    (r"/index/global_set/initpasswd/", InitPasswdHandler),
    (r"/index/global_set/disbleuser/", DisbleUserHandler),
    (r"/index/global_set/addproject/", AddProjectHandler),
    (r"/index/global_set/getauth/", GetAuthHandler),
    (r"/index/global_set/editauth/", EditAuthHandler),
    (r"/index/info_help/", InfoHelpHandler),
    (r"/index/info_help/edituser/", EditUserHandler),
    (r"/static/(.*)", tornado.web.StaticFileHandler, {"path": "static"}),
    (r".*", NotFoundPage),
],  **settings)


if __name__ == "__main__":
    listen_ip =  sys.argv[1]
    listen_port =  sys.argv[2]
    application.listen(listen_port, listen_ip)
    tornado.ioloop.IOLoop.instance().start()

